package com.poisonh.unifiedauth.dialog;

import android.app.DialogFragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;

import com.poisonh.unifiedauth.R;
import com.poisonh.unifiedauth.widget.IndicatorWheelView;

import java.util.Arrays;

/**
 * 锁屏时间选择器
 * Created by PoisonH on 2016/7/6.
 */
public class ChooseTimeDialogFragment extends BaseDialogFragment implements View.OnClickListener
{
    private final String[] PLANETS = new String[]{"15秒", "30秒", "1分钟", "2分钟", "5分钟", "10分钟", "永不"};

    private Button mBtnTimeSure;
    private String mStrContent = "2分钟";

//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
//    {
//        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
//        View view = inflater.inflate(R.layout.layout_dialog_choosetime, null);
//        return view;
//    }

    @Override
    protected View loadView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        return inflater.inflate(R.layout.layout_dialog_choosetime, null);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState)
    {
        super.onViewCreated(view, savedInstanceState);

        IndicatorWheelView wv = (IndicatorWheelView) view.findViewById(R.id.iwv_choosetimedialog);
        mBtnTimeSure = (Button) view.findViewById(R.id.btn_time_sure);
        mBtnTimeSure.setOnClickListener(this);
        //设置默认选择项
        wv.setOffset(2);
        wv.setItems(Arrays.asList(PLANETS));
        wv.setSeletion(3);
        wv.setOnWheelViewListener(new IndicatorWheelView.OnWheelViewListener()
        {
            @Override
            public void onSelected(int selectedIndex, String item)
            {
                mStrContent = item;
            }
        });
    }

    @Override
    public void onClick(View v)
    {
        switch (v.getId())
        {
            case R.id.btn_time_sure:
                ChooseTimeListener listener = (ChooseTimeListener) getActivity();
                listener.onChooseTimeListener(mStrContent);
                this.dismiss();
                break;
        }
    }

    public interface ChooseTimeListener
    {
        void onChooseTimeListener(String time);
    }
}
